package com.wanxi.education.controller.front;

import com.wanxi.education.common.CommonResult;
import com.wanxi.education.model.vo.statistic.CertCategoriesVO;
import com.wanxi.education.model.vo.statistic.RankOfStudentPurchasedCourseVO;
import com.wanxi.education.service.BStatisticService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;
import java.util.Set;

/**
 * @Author: zhe
 * @Date: 2021/9/24 14:05
 * @Description: B端统计管理
 * @Version: 1.0
 */
@Api(tags = "合作机构统计API")
@RestController
@RequestMapping("/b-statistics")
public class BStatisticController {

    @Autowired
    private BStatisticService bStatisticService;

    @ApiOperation("证书分类数量API")
    @GetMapping("/number-of-cert-categories")
    public CommonResult numberOfCertCategories() {
        Set<CertCategoriesVO> certCategoriesVOSet = bStatisticService.numberOfCertCategories();
        return CommonResult.success(certCategoriesVOSet);
    }

    /**
     * 需要获取到登录机构负责人的ID
     * loginBId
     * @return
     */
    @ApiOperation("机构学员购买课程总数前七API")
    @GetMapping("/rank-of-student-purchased-course")
    public CommonResult rankOfStudentPurchasedCourse(HttpServletRequest request) {
        Long loginBId = (Long) request.getSession().getAttribute("loginBId");
        if (loginBId == null) {
            return CommonResult.unauthorized("请重新登录后重试！");
        }
        Set<RankOfStudentPurchasedCourseVO> rankOfStudentPurchasedCourseVOSet = bStatisticService.rankOfStudentPurchasedCourse(loginBId);
        return CommonResult.success(rankOfStudentPurchasedCourseVOSet);
    }

    /**
     * 需要获取到登录机构负责人的ID
     * loginBId
     * @return
     */
    // todo 返回的是具体数字值即可
    @ApiOperation("当前机构注册学员总数API")
    @GetMapping("/total-number-of-employees")
    public CommonResult totalNumberOfEmployees(HttpServletRequest request) {
        Long loginBId = (Long) request.getSession().getAttribute("loginBId");
        if (loginBId == null) {
            return CommonResult.unauthorized("请重新登录后重试！");
        }
        Map<String,Object> map = bStatisticService.totalNumberOfEmployees(loginBId);
        return CommonResult.success(map);
    }

    /**
     * 需要获取到登录机构负责人的ID
     * loginBId
     * @return
     */
    // todo 返回的是具体数字值即可
    @ApiOperation("当前机构总购课数量API")
    @GetMapping("/total-number-of-course-purchased")
    public CommonResult totalNumberOfCoursePurchased(HttpServletRequest request) {
        Long loginBId = (Long) request.getSession().getAttribute("loginBId");
        if (loginBId == null) {
            return CommonResult.unauthorized("请重新登录后重试！");
        }
        Map<String,Object> map = bStatisticService.totalNumberOfCoursePurchased(loginBId);
        return CommonResult.success(map);
    }


}
